const Token = appRequire('common/token');
const userModel = appRequire('models/user');

const exportObj = {
  verifyToken
};

module.exports = exportObj;

// 验证Token中间件
async function verifyToken(req, res, next) {
  if (req.path === '/login') return next();
  let token = req.headers['token'];
  let tokenVerifyObj = Token.decrypt(token);
  if (tokenVerifyObj.token) {
    let userIds = tokenVerifyObj.data
    let thisUser = await userModel.user.findOne({
      where: {
        objectId: userIds.uid
      }
    })
    /*if (thisUser.isDisabled) {
      return res.json({
        code: 0,
        msg: "账户已禁用",
        data: ''
      })
    }*/

    
    req.body.uid = userIds.uid;
    next()
  } else {
    res.json(Constant.NO_LOGIN)
  }
}